package com.dom.stor.dao.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dom.stor.dao.entity.TGoodVarietyTbl;
import com.dom.stor.dao.mapper.TGoodVarietyTblMapper;
import com.dom.stor.dao.service.ITGoodVarietyTblService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * B_商品品种代码表 服务实现类
 * </p>
 *
 * @author xllei
 * @since 2018-11-17
 */
@Service
public class TGoodVarietyTblServiceImpl extends ServiceImpl<TGoodVarietyTblMapper, TGoodVarietyTbl> implements ITGoodVarietyTblService {
    @Override
    public Map<Integer, String> getVarietyNameList(Integer memCode) {
        List<TGoodVarietyTbl> records = getVarietyList(memCode);
        return records.stream().collect(Collectors.toMap(TGoodVarietyTbl::getVarietyCode, entity->{return entity.getVarietyName();}));
    }

    private List<TGoodVarietyTbl> getVarietyList(Integer memCode){
        Wrapper<TGoodVarietyTbl> wrapper = new EntityWrapper<>();
        wrapper.eq("mem_code", memCode)
                .orderBy("id");
        return this.selectList(wrapper);
    }
}
